﻿using System;
using SharePoint.Diagnostics;

namespace Eneta.Portal.Common.Loggers
{
    /// <summary>
    /// <see cref="ILogger"/> implementation that uses Unified Logging System (SharePoint default logs). 
    /// This implementation works on WSS and MOSS without modifications.
    /// </summary>
    public class UlsLogger : ILogger
    {
        /// <summary>
        /// Writes the informative message to log.
        /// </summary>
        /// <param name="message">The message to log.</param>
        /// <param name="source">The source of message.</param>
        public void LogInfo(string message, string source)
        {
            Trace.LogInformationEvent(message, source);
        }

        /// <summary>
        /// Writes the warning message to log.
        /// </summary>
        /// <param name="message">The message to log.</param>
        /// <param name="source">The source of message.</param>
        public void LogWarning(string message, string source)
        {
            Trace.LogMessage(message, TraceSeverity.WarningEvent, source);
        }

        /// <summary>
        /// Logs the exception.
        /// </summary>
        /// <param name="ex">The exception to log.</param>
        public void LogException(Exception ex)
        {
            Trace.LogError(ex, ex.Source);
        }
    }
}
